package main

import "fmt"

func permute(nums []int) [][]int {
	res := [][]int{}
	var helper func(list []int, m map[int]bool)
	helper = func(list []int, m map[int]bool) {
		if len(list) == len(nums) {
			res = append(res, append([]int{}, list...))
			return
		} else {
			for i := 0; i < len(nums); i++ {
				if i > 0 && nums[i-1] == nums[i] && m[i-1] == false {
					continue
				}
				if _, ok := m[i]; !ok {
					m[i] = true
					list = append(list, nums[i])
					helper(list, m)
					list = list[:len(list)-1]
					delete(m, i)
				}
			}
		}
	}
	helper([]int{}, make(map[int]bool))
	return res
}

func main() {
	fmt.Println(permute([]int{1, 1, 2}))
}
